package com.cn.xiaonuo.slbfinances.slbagents.controller;

import cn.hutool.core.convert.Convert;
import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.common.utils.ApiJsonModel;
import com.cn.xiaonuo.slbfinances.slbagents.service.IPvTradeService;
import com.cn.xiaonuo.slbfinances.slbagents.service.ISalesOperationsService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(description = "申请代理接口")
@CrossOrigin
@RestController
public class SalesOperationsController {

    @Resource
    private ISalesOperationsService salesOperationsService;
    @Resource
    private IPvTradeService pvTradeService;

    //13.提成用户列表
    @ApiOperation(value = "代理数据汇总/结算-搜了宝-->财务结账-列表页", notes = "代理数据汇总/结算-搜了宝-->财务结账-列表页")
    @ApiJsonModel({
            @ApiModelProperty(name = "paymentUserId", value = "支付用戶ID", example = "10086", required = true),
            @ApiModelProperty(name = "realName", value = "真实姓名", example = "张三", required = true),
            @ApiModelProperty(name = "startTime", value = "开始时间", example = "2021-10-10 10:10:10", required = true),
            @ApiModelProperty(name = "endTime", value = "结束时间", example = "2021-12-10 10:10:10", required = true),
            @ApiModelProperty(name = "pageNo", value = "页数", required = true),
            @ApiModelProperty(name = "pageSize", value = "长度", required = true)
    })
    @PostMapping(value ="/api/salesOperations/agentUserList")
    public BusinessMessage agentUserList(@RequestBody Map<String, Object> params ) {
        String paymentUserId= Convert.toStr(params.get("paymentUserId"));
        String realName=Convert.toStr(params.get("realName"));
        String startTime=Convert.toStr(params.get("startTime"));
        String endTime=Convert.toStr(params.get("endTime"));
        Integer pageNo=Convert.toInt(params.get("pageNo"));
        Integer pageSize=Convert.toInt(params.get("pageSize"));
        return salesOperationsService.agentUserList(paymentUserId, realName, startTime, endTime, pageNo, pageSize);
    }

    //11.结款用户订单明细
    @ApiOperation(value = "代理数据汇总/结算-搜了宝-->搜了宝-->结账记录", notes = "代理数据汇总/结算-搜了宝-->搜了宝-->结账记录")
    @ApiJsonModel({
            @ApiModelProperty(name = "paymentUserId", value = "支付用戶ID", example = "10086", required = true),
            @ApiModelProperty(name = "startTime", value = "开始时间", example = "2021-10-10 10:10:10", required = true),
            @ApiModelProperty(name = "endTime", value = "结束时间", example = "2021-12-10 10:10:10", required = true),
            @ApiModelProperty(name = "pageNo", value = "页数", required = true),
            @ApiModelProperty(name = "buyerName", value = "购买者名称", example = "张三", required = true),
            @ApiModelProperty(name = "productName", value = "产品名称", example = "搜了宝水", required = true),
            @ApiModelProperty(name = "pageSize", value = "长度", required = true)
    })
    @PostMapping(value ="/api/salesOperations/paymentOrderList")
    public BusinessMessage paymentOrderList(@RequestBody Map<String, Object> params) {
        String paymentUserId=Convert.toStr(params.get("paymentUserId"));
        String startTime=Convert.toStr(params.get("startTime"));
        String endTime=Convert.toStr(params.get("endTime"));
        Integer pageNo=Convert.toInt(params.get("pageNo"));
        Integer pageSize=Convert.toInt(params.get("pageSize"));
        String buyerName=Convert.toStr(params.get("buyerName"));
        String productName=Convert.toStr(params.get("productName"));
        return salesOperationsService.paymentOrderList(paymentUserId, startTime, endTime, pageNo, pageSize, buyerName, productName);
    }

    //16.查看代理条件进度
    @ApiOperation(value = "搜了宝-->代理分润进度查询", notes = "搜了宝-->代理分润进度查询")
    @ApiJsonModel({
            @ApiModelProperty(name = "userId", value = "用戶ID", example = "10086", required = true)
    })
    @PostMapping(value ="/api/salesOperations/queryAgentCondition")
    public BusinessMessage queryAgentCondition(@RequestBody Map<String, Object> params) {
        String userId=Convert.toStr(params.get("userId"));
        return salesOperationsService.queryAgentCondition(userId);
    }

    @ApiOperation(value = "搜了宝-->匀贸兑酒记录", notes = "搜了宝-->匀贸兑酒记录")
    @PostMapping(value ="/api/salesOperations/financeExchangeList")
    public BusinessMessage financeExchangeList(@RequestBody Map<String,Object> param) {
        Integer pageNo=Convert.toInt(param.get("pageNo"));
        Integer pageSize=Convert.toInt(param.get("pageSize"));
        String statTime=Convert.toStr(param.get("statTime"));
        String endTime=Convert.toStr(param.get("endTime"));
        String accounts=Convert.toStr(param.get("accounts"));
        String userId=Convert.toStr(param.get("userId"));
        String productId=Convert.toStr(param.get("productId"));
        return pvTradeService.financeExchangeList(pageNo, pageSize, statTime, endTime, accounts, userId, productId);
    }

    @ApiOperation(value = "搜了宝-->搜了宝-->结账记录-明细", notes = "搜了宝-->搜了宝-->结账记录-明细")
    @ApiJsonModel({
            @ApiModelProperty(name = "paymentUserId", value = "支付用戶ID", example = "10086", required = true),
            @ApiModelProperty(name = "startTime", value = "开始时间", example = "2021-10-10 10:10:10", required = true),
            @ApiModelProperty(name = "endTime", value = "结束时间", example = "2021-12-10 10:10:10", required = true),
            @ApiModelProperty(name = "buyerName", value = "购买人姓名", example = "张三", required = true),
            @ApiModelProperty(name = "productName", value = "产品名称", example = "搜了宝水", required = true),
            @ApiModelProperty(name = "paymentStartTime", value = "支付开始时间", example = "2021-10-10 10:10:10", required = true),
            @ApiModelProperty(name = "paymentEndTime", value = "支付结束时间", example = "2021-12-10 10:10:10", required = true),
            @ApiModelProperty(name = "paymentState", value = "支付状态", example = "1,2,3,4....", required = true),
            @ApiModelProperty(name = "pageNo", value = "页数", example = "1",required = true),
            @ApiModelProperty(name = "pageSize", value = "长度", example = "10",required = true)
    })
    @PostMapping(value = "/api/salesOperations/agentOrderList")
    public BusinessMessage agentOrderList(@RequestBody Map<String, Object> params){
        String paymentUserId=Convert.toStr(params.get("paymentUserId"));
        String startTime=Convert.toStr(params.get("startTime"));
        String endTime=Convert.toStr(params.get("endTime"));
        Integer pageNo=Convert.toInt(params.get("pageNo"));
        Integer pageSize=Convert.toInt(params.get("pageSize"));
        String buyerName=Convert.toStr(params.get("buyerName"));
        String productName=Convert.toStr(params.get("productName"));
        String paymentStartTime=Convert.toStr(params.get("paymentStartTime"));
        String paymentEndTime=Convert.toStr(params.get("paymentEndTime"));
        String paymentState=Convert.toStr(params.get("paymentState"));
        return salesOperationsService.agentOrderList(paymentUserId,startTime,endTime,pageNo, pageSize,buyerName,productName,paymentStartTime, paymentEndTime,paymentState);
    }


    @ApiOperation(value = "搜了宝-代理数据汇总-财务结账", notes = "搜了宝-代理数据汇总-财务结账")
    @ApiJsonModel({
            @ApiModelProperty(name = "paymentUserId", value = "支付用戶ID", example = "10086", required = true),
            @ApiModelProperty(name = "startTime", value = "开始时间", example = "2021-10-10 10:10:10", required = true),
            @ApiModelProperty(name = "endTime", value = "结束时间", example = "2021-12-10 10:10:10", required = true),
            @ApiModelProperty(name = "realName", value = "真实姓名", example = "张三", required = true),
            @ApiModelProperty(name = "pageNo", value = "页数", example = "1",required = true),
            @ApiModelProperty(name = "pageSize", value = "长度", example = "10",required = true)
    })
    @PostMapping(value = "/api/salesOperations/paymentUserList")
    public BusinessMessage paymentUserList(@RequestBody Map<String, Object> params){
        String paymentUserId=Convert.toStr(params.get("paymentUserId"));
        String realName=Convert.toStr(params.get("realName"));;
        String startTime=Convert.toStr(params.get("startTime"));
        String endTime=Convert.toStr(params.get("startTime"));
        Integer pageNo=Convert.toInt(params.get("pageNo"));
        Integer pageSize=Convert.toInt(params.get("pageSize"));
        return salesOperationsService.paymentUserList(paymentUserId,realName,startTime,endTime,pageNo, pageSize);
    }
}
